package com.swf.common.jar;

import com.swf.common.utils.*;

/**
 * description: 存放jar信息
 * @version 1.0 2013-5-16
 * @author shenwf
 */
public class Jar {
	/**
	 * jar包名称
	 */
	private String name;
	/**
	 * jar包路径
	 */
	private String path;
	/**
	 * 是否添加
	 */
	private boolean add = true;
	
	
	public Jar() {
	}
	
	public Jar(String name) {
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}

	public boolean isAdd() {
		return add;
	}

	public void setAdd(boolean add) {
		this.add = add;
	}
	/**
	 * 返回jar的XML格式,相关字段不进行XML转义
	 */
	@Override
	public String toString() {
		return toString(0);
	}
	
	/**
	 * 返回jar的XML格式,相关字段path进行XML转义
	 * @return
	 */
	public String toEscapeString() {
		return toEscapeString(0);
	}
	/**
	 * 返回jar的XML格式,相关字段path进行XML转义
	 * @param tabCount 前面空格个数
	 * @return xml 如  <jar name="dd" path="c:\a\b/&quot;c" add="false"/> 
	 */
	public String toEscapeString(int tabCount) {
		String tab = FwsStringUtils.repeat(" ", tabCount);
		StringBuffer sb = new StringBuffer();
		sb.append(FwsStringUtils.addBefore("<jar name=\""+this.name +"\"",tab));
		if (path!=null){
			sb.append(" path=\"" + FwsStringEscapeUtils.escapeXml(this.path)+"\"");
			}
		sb.append(" add=\""+add+"\"/>");
		return sb.toString();
	}
	
	/**
	 * 返回jar的XML格式,相关字段不进行XML转义
	 * @param tabCount
	 * @return
	 */
	public String toString(int tabCount){
		return FwsStringEscapeUtils.unescapeXml(toEscapeString(tabCount));
	}
}